<meta charset="UTF-8">
<?php
require('lib/init.php');
//添加栏目PHP
if (empty($_POST)){
    include (ROOT . '/view/admin/catadd.html');
}else{
    $conn = mysqli_connect('localhost' , 'root' , '');
    mysqli_query($conn,'use blog;');
    mysqli_query($conn,'set names utf8;');
//    检测栏目是否为空
    $cat['cat_name'] =trim($_POST['catname']);
    if (empty($cat['cat_name'])){
        error  ('栏目不能为空');
        exit();
    }
//  检测栏目是否已经存在
    $sql = "select * from cat where cat_name = '$cat[cat_name]'";
    $rs = mGetRow($sql);
    if ($rs != 0){
        error  ('栏目已经存在');
        exit();
    }
    //$sql = "insert into cat (cat_name) values ('$cat[catname]')";
    if (!mExec('cat',$cat,'insert')){
        echo '栏目添加失败！';
    } else{
       succ('栏目插入成功！');
    }


}


?>
